home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 464 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  6.4 KB

  1. Path: nntp.teleport.com!sschaem
  2. From: sschaem@teleport.com (Stephan Schaem)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: PPC compilers
  5. Date: 8 Jan 1996 10:33:22 GMT
  6. Organization: Teleport - Portland's Public Access (503) 220-1016
  7. Message-ID: <4cqrti$f6u@maureen.teleport.com>
  8. References: <john.hendrikx.40ka@grafix.xs4all.nl> <jasonb.820051107@cs.uwa.edu.au> <4c9i2l$h3i@sunsystem5.informatik.tu-muenchen.de> <4ck47h$g07@maureen.teleport.com> <19960106.4EE928.CF59@sisyphus.demon.co.uk> <4cokkg$415@maureen.teleport.com> <19960107.533250.14585@sisyphus.demon.co.uk>
  9. NNTP-Posting-Host: kelly.teleport.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Dave.Sparks@sisyphus.demon.co.uk wrote:
  13. : >>>>> "SS" == Stephan Schaem <sschaem@teleport.com> writes:
  14.  
  15. :   SS> Dave.Sparks@sisyphus.demon.co.uk wrote:
  16. :   >> >>>>> "SS" == Stephan Schaem <sschaem@teleport.com> writes:
  17.  
  18. :   >> SS> I cant see how people can write code without knowing what data or
  19. :   >> SS> type they manipulate...
  20.  
  21. :   >> Real-world programmers do it all the time.  If you ever want to
  22.  
  23. :   SS>  So you do math operation without knowing that your destination need
  24. :   SS> to be a float or a 2 byte int?
  25.  
  26. : Yes.  This is a trivial example of polymorphism.
  27.  
  28.  polymorphism?
  29.  
  30.  int a,b,c;
  31.  
  32.  ...
  33.  a = b /c;
  34.  a *= result;
  35.  ...
  36.  struct.float = a;
  37.  
  38.  I dunno , I just find it puzzling to declar variable without giving
  39.  a care of what its usage will be. You programing practice is VERY unwise...
  40.  
  41. :   >> join us, you'll have to learn to do it too.  One of many examples
  42.  
  43. :   SS>  Real world = commercial? I'm deep in it, thanks
  44.  
  45. : Is your employer happy that you're so out of touch with modern
  46. : programming practices?
  47.  
  48.  I actually think that they like that I know what I'm doing VS 
  49.  programing on asuption (polymorphism?)
  50.  
  51. :   >> is the ANSI C definition of the 'clock' function: the value returned
  52. :   >> is of type 'clock_t', which is defined in a system-dependent header
  53. :   >> file.  SAS/C defines 'clock_t' to be an unsigned 32-bit value, but
  54. :   >> other implementations can (and do) define it to be signed or even
  55. :   >> 64-bit floating-point.  Since the C arithmetic operations (add,
  56. :   >> subtract, multiply, divide) are overloaded (can be used on values of
  57. :   >> ...
  58.  
  59. :   SS>  ANSI for good reason decided on a minimal size of all its basic
  60. :   SS> type.  This to help you the program choose the right type for your
  61. :   SS> need.
  62.  
  63. :   SS>  The only way you dont care is if you typedef all the ANSI type.
  64.  
  65. :   SS>  So you created a structure to hold clock value with ulong? now
  66. :   SS> recompile this on the system using a clock size of 64bit... where did
  67. :   SS> the upper 32bit goes... you know have code that is broken.
  68.  
  69. : I know better than to declare a value as unsigned long when I'm
  70. : going to assign a clock_t to it.  And if I did, I'd lose the
  71. : fractional part of a floating-point clock_t, not the upper 32 bits.
  72.  
  73.  You said yourself after peeking at the .h that clock_t was a ulong.
  74.  But you know better then not using a ulong... ? Should I assume
  75.  you alway use the largest data type available,double ? (What a waist)
  76.  And you mean you would loose the fractional part of clock_t if you
  77.  used ulong , not the upper 32bits? This make absolutly no sense since
  78.  we are talking about interger types.(BTW copy 0x00000001 into a 2byte int,
  79.  you will loose the upper 16bit... )
  80.  
  81.  If the header file was programmed correctly it would not use ANSI data
  82.  type directly.... Anyway, you must know that since you are the cream of
  83.  the real world programmer with polymorhism programming.
  84.  
  85. :   SS>  ex of something that wont break with a recompile:
  86.  
  87. :   SS>  typedef short point2d
  88.  
  89. :   SS>  struct    RECTANGLE {     point2d    x1;     point2d    y1;     point2d    x2;
  90. :   SS> point2d    y2; } rectangle, *rectangle;
  91.  
  92. :   SS>  then you declare you variable using rectangle, or point2d
  93.  
  94. :   SS>  Then if later you find out in your design you need to use long (Or
  95. :   SS> create another set of include for another platform), you can just
  96. :   SS> chnage point2d... I rarely see that done... anyway
  97.  
  98. : So you don't know that many fields in the UNIX header files have
  99. : changed from 16 bits to 32 (for example the user-id and group-id
  100. : in the directory-handling structures)?  You have led a sheltered life.
  101.  
  102.  I did live a sheltered life? Is this a call for sympathy, for all the
  103.  hardhacks you went trought??
  104.  
  105.  Anyway:
  106.  
  107.  Where those field public?
  108.  
  109.  ex: if those field where defined with ushort with no mention of extension
  110.  people could have wrote function to set those field using ushort has
  111.  function parameter... now with the new header file you need to go back
  112.  and modify your functions prototyping otherwise they break.
  113.  
  114. :   SS>  ...
  115.  
  116. :   SS>  about loop counter size... should I use ulong and forget about it,
  117. :   SS> or use ushort to be sure of optimal speed on my target CPU and
  118. :   SS> remember my declaration type in case I want to use it for a loop
  119. :   SS> count bigger then 65535?. (this result in a sub/bcc vs dbcc encoding
  120. :   SS> on 680x0... )
  121.  
  122. : target CPU?  How quaint ...
  123.  
  124.  But target CPU is something that come up often in the real world of
  125.  programming... oh, forgot you think you are part of it.
  126.  C compiler cannot change and optimize the variable type at compile
  127.  time, the compiler take your word for it that you done a wise choice.
  128.  Use float everywhere for all I care, and see how your code compile
  129.  on a 68000.
  130.  
  131. : And why use subq/bcc rather than dbcc, if speed is all-important?
  132. : It's easy enough to decrement and check the upper word whenever
  133. : the lower word has just expired, so why assume that a compiler
  134. : will generate the slower code?  In any case, if you're using the
  135. : loop counter to index an array, the compiler will probably have
  136. : transformed the loop counter and be subtracting the size of an
  137. : array element, to avoid the use of a (slow) multiply instruction in the
  138. : body of the loop; it couldn't use dbcc anyway.  You don't get
  139. : optimal speed by optimizing the instructions, but by optimizing
  140. : the algorithm.
  141.  
  142.  A 32bit counter need to use subq/bcc or a nested swap/dbcc/swap/dbcc.
  143.  If you know you never need >65535 iteration why use a 32bit counter?
  144.  Anyway, if you use an array index in your loop its probly fine on
  145.  some risc CPU that doesn't support 'complex' addressing modes, but
  146.  on a 680x0 I suggest auto incrementing your array pointer.
  147.  
  148.  The way you get optimal speed is optimizing the optimal algorithim.
  149.  If you stop at the algorithm you loose... Optimizing at this stage
  150.  will give an exponential result on the work you done on the algorithm.
  151.  And usually this stage is done in assembler.
  152.  
  153.  Stephan
  154.